<!--设置模块唯一ID-->
<div id="gcb_gongchengguanli_add">
<!--标题、面包屑-->
<section class="content-header">
    <h1>
        工程管理
    </h1>
    <ol class="breadcrumb">
        <li><a href="#"><i class="fa fa-dashboard"></i> 首页</a></li>
        <li>工程部</li>
        <li>工程管理</li>
        <li class="active">工程登记表</li>
    </ol>
</section>
<!--列表-->
<section class="content">

</section>
<!--添加、修改弹出层-->
<script type="text/template" data-for="tp_editor">
    <form role="form" class="form-horizontal">
        <div class="u-area">
            <div class="form-group">
                <label class="col-sm-2 control-label">编号：<%=data.p1?data.p1:''%></label>
                <div class="col-sm-4">
                    <input type="text" class="form-control"
                           value="<%=data.p1?data.p1:''%>" disabled>
                </div>

                <label class="col-sm-2 control-label">状态</label>
                <div class="col-sm-4">
                    <select class="form-control" name="p2">
                        <option>草稿</option>
                        <option>已缴费</option>
                        <option>未交费</option>
                        <option>已趸交</option>
                        <option>已签署</option>
                    </select>
                </div>
            </div>
        </div>
        <div class="u-box">
            <div class="u-box-header">
                <h3>操作人信息</h3>
            </div>
            <div class="u-area">
                <div class="form-group">
                    <label class="col-sm-2 control-label">操作人</label>
                    <div class="col-sm-4">
                        <input type="text" class="form-control" name="p3"
                               value="<%=data.p3?data.p3:''%>" disabled>
                    </div>

                    <label class="col-sm-2 control-label">当前时间</label>
                    <div class="col-sm-4">
                        <input type="text" class="form-control" name="p4"
                               value="<%=data.p4?data.p4:''%>" disabled>
                    </div>
                </div>
            </div>
        </div>
        <div class="u-box ">
            <div class="u-box-header ">
                <h3>基本信息</h3>
            </div>
            <div class="u-area">
                <div class="u-area">
                    <div class="form-group">
                        <label class="col-sm-2 control-label">建设单位</label>
                        <div class="col-sm-10">
                            <input type="text" class="form-control" name="p5"
                                   value="<%=data.p5?data.p5:''%>">
                        </div>

                    </div>

                    <div class="form-group">
                        <label class="col-sm-2 control-label">项目名称</label>
                        <div class="col-sm-4">
                            <input type="text" class="form-control" name="p7"
                                   value="<%=data.p7?data.p7:''%>" disabled>
                        </div>

                        <label class="col-sm-2 control-label">完工情况</label>
                        <div class="col-sm-4">
                            <select class="form-control">
                                <option>在建</option>
                                <option>养护</option>
                                <option>完成</option>
                            </select>
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-sm-2 control-label">进度</label>
                        <div class="col-sm-4">
                            <input type="text" class="form-control" name="p9"
                                   value="<%=data.p9?data.p9:''%>">
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-sm-2 control-label">备注</label>
                        <div class="col-sm-10">
                            <textarea type="text" class="form-control" name="p9">
                                <%=data.p9?data.p9:''%>
                            </textarea>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="u-box ">
            <div class="u-box-header ">
                <h3>合同信息</h3>
            </div>
            <div class="u-area">

                <div class="form-group">
                    <label class="col-sm-2 control-label">合同金额</label>
                    <div class="col-sm-4">
                        <input type="text" class="form-control" name="p3"
                               value="<%=data.p3?data.p3:''%>" >
                    </div>

                    <label class="col-sm-2 control-label">合同时间</label>
                    <div class="col-sm-4">
                        <input type="text" class="form-control" name="p4"
                               value="<%=data.p4?data.p4:''%>" >
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-2 control-label"></label>
                    <div class="col-sm-10">
                        <table class="table table-bordered table-striped table-hover u-inline-table">
                            <thead>
                            <th>进度名称</th>
                            <th>金额</th>
                            <th>操作</th>
                            </thead>
                            <tbody>

                            </tbody>
                        </table>
                    </div>
                </div>

                <div class="border"></div>

                <div class="form-group">
                    <label class="col-sm-2 control-label">累计收入</label>
                    <div class="col-sm-4">
                        <input type="text" class="form-control" name="p3"
                               value="<%=data.p3?data.p3:''%>" disabled>
                    </div>

                    <label class="col-sm-2 control-label">实际结算</label>
                    <div class="col-sm-4">
                        <input type="text" class="form-control" name="p4"
                               value="<%=data.p4?data.p4:''%>" disabled>
                    </div>
                </div>

                <div class="form-group">
                    <label class="col-sm-2 control-label">预算</label>
                    <div class="col-sm-4">
                        <input type="text" class="form-control" name="p3"
                               value="<%=data.p3?data.p3:''%>" disabled>
                    </div>

                    <label class="col-sm-2 control-label">累计支出</label>
                    <div class="col-sm-4">
                        <input type="text" class="form-control" name="p4"
                               value="<%=data.p4?data.p4:''%>" disabled>
                    </div>
                </div>
            </div>
        </div>
        <div class="box-footer">
            <button type="submit" class="btn btn-primary pull-right">提交</button>
        </div>
    </form>
</script>

<script>
    USEN(function () {
        //模块ID(全系统唯一)
        var tableId = "#gcb_gongchengguanli";
        var id = "#gcb_gongchengguanli_add";

        //定义页面变量
        var $el = $(id);
        var $editor = $el.children('script[data-for=tp_editor]');

        $.ajax({
            url:"./simdata/common_add_action.json",
            success:function(data){
                $el.children(".content").html(function(){
                    return _.template($editor.html())({
                        data:data
                    })
                });
                var $table =  $(id+' table.table tbody');
                var tr = '<tr><td editor></td><td editor></td><td><a href="javascript:;" class="add"> <i class="fa fa-plus"></i></a><a href="javascript:;" class="reduce"> <i class="fa fa-minus"></i></a></td></tr>';
                $table.append(tr).on('click','td[editor]',function(){
                    if($(this).find('input').length!=0) return false;
                    var val = $(this).text();
                    $(this).html('<input type="text" value="' + val + '">').children('input').trigger('focus');

                    $(this).siblings('td').each(function(){
                        $(this).html($(this).find("input").val())
                    })
                }).on('blur','input',function(){
                    $(this).parent('td').html($(this).val());
                }).on('click','a.add',function(){
                    $table.append(tr);
                }).on('click','a.reduce',function(){
                    if($table.find("tr").length > 1)
                        $(this).closest('tr').remove();
                });
                //提交表单
                $el.find("form").ajaxForm({
                    url: './simdata/common_add_action.json',
                    beforeSubmit: function (data) {
                        //console.log("数据提交之前.")
                    },
                    success: function (data, state, obj) {
                        USEN.notifyAlert({
                            title: "提示:",
                            content: '操作成功,刷新列表'
                        });
                        USEN.getDatatable(tableId + ' table.table').ajax.reload();
                        USEN.closeActiveTab();
                    }
                })

                $el.find("select").css('width','98%').select2({
                    dropdownParent:$el
                });
                $el.find("input[data-plugin=date]").datepicker({
                    autoclose: true
                })
            }
        })

    });
</script>
</div>